package com.lb.jwitter.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;

import com.lb.jwitter.service.ConditionReport;
import com.lb.jwitter.service.TblDKMHDotDKHocVien;
import com.lb.jwitter.service.TblDKMHDotDKHocVienService;
import com.lb.jwitter.service.TblDKMHTaiKhoanHocVien;
import com.lb.jwitter.service.TblDKMHTaiKhoanHocVienService;
import com.lb.jwitter.service.TblMenu;
import com.lb.jwitter.service.TblMenuService;
import com.lb.jwitter.service.TblQuyenChiTietService;
import com.lb.jwitter.service.TblQuyenMenu;
import com.lb.jwitter.service.TblQuyenMenuService;
import com.lb.jwitter.service.TblTaiKhoan;
import com.lb.jwitter.util.ApplicationContextProvider;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

@ContextConfiguration(locations="classpath:beans.xml") 
public class GetDanhSachDotDKAction {

	private TblDKMHTaiKhoanHocVien tblDKMHTaiKhoanHocVien;
	public TblDKMHTaiKhoanHocVien getTblDKMHTaiKhoanHocVien() {
		return tblDKMHTaiKhoanHocVien;
	}

	public void setTblDKMHTaiKhoanHocVien(
			TblDKMHTaiKhoanHocVien tblDKMHTaiKhoanHocVien) {
		this.tblDKMHTaiKhoanHocVien = tblDKMHTaiKhoanHocVien;
	}

	private TblDKMHTaiKhoanHocVienService tblDKMHTaiKhoanHocVienService;
	
	private TblDKMHDotDKHocVienService tblDKMHDotDKHocVienService;
	private List<TblDKMHDotDKHocVien> tblDKMHDotDKHocViens;
	  
	public List<TblDKMHDotDKHocVien> getTblDKMHDotDKHocViens() {
		return tblDKMHDotDKHocViens;
	}

	public void setTblDKMHDotDKHocViens(
			List<TblDKMHDotDKHocVien> tblDKMHDotDKHocViens) {
		this.tblDKMHDotDKHocViens = tblDKMHDotDKHocViens;
	}
	
	private int hocKyId;

	public int getHocKyId() {
		return hocKyId;
	}

	public void setHocKyId(int hocKyId) {
		this.hocKyId = hocKyId;
	}

	@Autowired // Injected by Spring 
	ApplicationContextProvider contextProvider; 
	 	 
	public String execute() throws Exception
	{

		Map session = ActionContext.getContext().getSession();
		tblDKMHTaiKhoanHocVien =  (TblDKMHTaiKhoanHocVien) session.get("taiKhoanHocVien");
	     if( tblDKMHTaiKhoanHocVien == null) return "noprivilege";
	     
	    ApplicationContext context = contextProvider.getApplicationContext(); 
	    
	    tblDKMHDotDKHocVienService = (TblDKMHDotDKHocVienService)  context.getBean("tbl_DKMH_DotDK_HocVienClient");
	    
		
		
		
		if(tblDKMHTaiKhoanHocVien != null){
			List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
		    { 
		        ConditionReport con = new ConditionReport(); 
		        con.setCol("hocVienId.id");
		        con.setValue1(tblDKMHTaiKhoanHocVien.getHocVienId().getId());
		        con.setOperator("eq");
		        cons.add(con);	
		    }
		    { 
		        ConditionReport con = new ConditionReport(); 
		        con.setCol("dotDKId.hocKyId.id");
		        con.setValue1(new Long(hocKyId));
		        con.setOperator("eq");
		        cons.add(con);	
		    }
		    
//		    { 
//		        ConditionReport con = new ConditionReport(); 
//		        con.setCol("khongDangKyYN");
//		        con.setValue1(false);
//		        con.setOperator("eq");
//		        cons.add(con);	
//		    }
		    
		    tblDKMHDotDKHocViens = tblDKMHDotDKHocVienService.findtblDKMHDotDKHocVienByCondition(cons,0, 0); 

		}
		session.remove("dotDKId");
		session.remove("trongHanDK");
		session.remove("ketQuaDangKys");
		
		return Action.SUCCESS;

	}


	
	
	
	
	
}
